package com.dianzhang.xsentinel;

import com.dianzhang.xsentinel.service.BusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author xingyulai
 * @date 2024/2/24 3:32 PM
 * @description
 **/
public class StartupListener implements ApplicationListener<ContextRefreshedEvent> {

    @Autowired
    private BusinessService businessService;

    ExecutorService executorService = Executors.newFixedThreadPool(8);

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {

        new Thread(() -> {


            //睡3s
            try {
                Thread.sleep(20000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

            for (int i = 0; i < 100; i++) {
                executorService.execute(() -> {
                    businessService.work();
                });
            }

        }).start();


    }
}
